#pragma once

#include <atlstr.h>
#include "tdd.h"
#include "tddassert.h"
#include <atlsecurity.h>

#include <stdlib.h>

// Defines some useful macros for verification 
// Old macros are used for error code, these are used for exceptions

// Argument success is output argument, should be a variable
// test whether the (args) has thrown out an exception
#define TEST_RESULT(args, success) \
    { \
        (success) = false; \
        try \
        { \
            (args); \
        } \
        catch(...) \
        { \
            (success) = true; \
        } \
    }

#define TEST_NO_EXCEPTION(args) \
    { \
        try \
        { \
            (args); \
        } \
        catch(...) \
        { \
            char str[150] = {0}; \
            sprintf(str, "Unexpected exception is thrown"); \
            TDD_FAILURE(str); \
        } \
    }

#define TEST_EXPECT_EXCEPTION(args) \
    { \
        try \
        { \
            (args); \
            char str[100] = {0}; \
            sprintf(str, "Exception expected in %.70s", #args); \
            TDD_FAILURE(str); \
        } \
        catch(...) {} \
    }

#define TEST_EXPECT_SPECIFIED_EXCEPTION(errorCode, args) \
    { \
        HRESULT hr = (errorCode); \
        try \
        { \
            (args); \
            char str[100] = {0}; \
            sprintf(str, "Exception expected in %.70s", #args); \
            TDD_FAILURE(str); \
        } \
        catch(...) \
        { \
            if(hr != ex.GetErrorCode()) \
            { \
                char str[150] = {0}; \
                sprintf(str, "Exception in %.80s: Error Code Expected <%x>, Actual <%x>", #args, hr, ex.GetErrorCode()); \
                TDD_FAILURE(str); \
            } \
        } \
    }
